<template>
  <div class="mt20 ml20 pr16">
    <!--基本信息-->
    <div class="common-form">设置推荐</div>
    <div class="ml20">
      <el-form>
        <el-form-item label="每日推荐：">
          <el-switch
            v-model="homeStatus"
            @change="homeChange"
          ></el-switch>
        </el-form-item>
        <el-form-item label="精选商品：">
          <el-switch
            v-model="selectedStatus"
            @change="selectedChange"
          ></el-switch>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import draggable from "vuedraggable";
export default {
  components: {},
  data() {
    return {
      homeStatus:false,
      selectedStatus:false,
      isProductUpload: false,
    };
  },
  inject: ["form"],
  created() {
    this.homeStatus = this.form.model.home_status == 1 ? true : false;
    this.selectedStatus = this.form.model.selected_status == 1 ? true : false;

  },
  methods: {
    //每日推荐
    homeChange(e) {
      console.log(e);
      this.form.model.home_status = e ? 1 : 0;
      console.log(e,this.form.model.home_status);
    },
    //精选商品
    selectedChange(e) {
      this.form.model.selected_status = e ? 1 : 0;
    },
    changeValue(e) {
      this.$forceUpdate();
    },
    /*打开上传图片*/
    openProductUpload: function () {
      this.isProductUpload = true;
    },

    /*上传商品图片*/
    returnProductImgsFunc(e) {
      if (e != null) {
        let imgs = this.form.model.image.concat(e);
        this.$set(this.form.model, "image", imgs);
      }
      this.isProductUpload = false;
    },

    /*删除商品图片*/
    deleteImg(index) {
      this.form.model.image.splice(index, 1);
    },
  },
};
</script>

<style>
.edit_container {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  line-height: 20px;
  color: #2c3e50;
}

.ql-editor {
  height: 400px;
}

.draggable-list {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
}
.draggable-list .wrapper > span {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.draggable-list .item {
  position: relative;
  width: 110px;
  height: 110px;
  margin-top: 10px;
  margin-right: 10px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #dddddd;
}

.draggable-list .delete-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 16px;
  height: 16px;
  background: red;
  line-height: 16px;
  font-size: 16px;
  color: #ffffff;
  display: none;
}

.draggable-list .item:hover .delete-btn {
  display: block;
}

.draggable-list .item img {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  max-height: 100%;
  max-width: 100%;
}

.draggable-list .img-select {
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px dashed #dddddd;
  font-size: 30px;
}

.draggable-list .img-select i {
  color: #409eff;
}
</style>
